package com.fengzai.election;

import com.fengzai.utils.ZkUtil;
import org.apache.curator.framework.CuratorFramework;

import java.util.concurrent.CountDownLatch;

/**
 * Created by  峰仔  on 2017-08-12
 *
 * Master选举
 */
public class MasterTest {
    //集群数
    private static int NUM = 5;
    private static CountDownLatch timerController = new CountDownLatch(NUM);

    public static void main(String[] args) throws Exception {
        CuratorFramework curatorFramework = ZkUtil.getInstace("master");
        for (int i = 0; i < NUM; i++) {
            int finalI = i;
            new Thread(() -> {
                try {
                    timerController.await();
                    MasterSelector masterSelector = new MasterSelector(curatorFramework);
                    masterSelector.start("服务器" + finalI);
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }).start();
            timerController.countDown();
        }

    }
}
